package com.appspot.bibtable.util;

import java.lang.reflect.Array;

public class ArrayUtility
{
	private ArrayUtility()
	{
		// Cannot be instanciated.
	}

	public static <T> boolean contains(T[] array, T value)
	{
		if (array == null)
		{
			return false;
		}

		if (value == null)
		{
			for (int index = 0; index < array.length; index++)
			{
				if (array[index] == null)
				{
					return true;
				}
			}
		}
		else
		{
			for (int index = 0; index < array.length; index++)
			{
				if (value.equals(array[index]))
				{
					return true;
				}
			}
		}
		return false;
	}

	public static <T> T[] concatenate(T[] head, T[] tail)
	{
		Object newArray = Array.newInstance(head.getClass().getComponentType(), head.length + tail.length);
		System.arraycopy(head, 0, newArray, 0, head.length);
		System.arraycopy(tail, 0, newArray, head.length, tail.length);
		return (T[])newArray;
	}
}
